home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / redakcyjne / programy / Weather Watcher Live 6.1.23 / WWL6123.exe / {app} / Skins / Interface / Splendid2 / Includes / DragDIV.js < prev    next >
Text File  |  2008-09-07  |  5KB  |  210 lines

  1. //********************************************
  2. //*  Global object to hold drag information  *
  3. //********************************************
  4. var dragObj = new Object();
  5. var dragLastTime;
  6. var dragLastX;
  7. var dragDirection;
  8. var dragging = false;
  9. var dragDistance;
  10. var creeping = false;
  11. var oldX;
  12. var isIE7 = ((navigator.userAgent).indexOf('MSIE 7.0') > -1);
  13.  
  14. function GetCurrentTime() 
  15. {    var my_current_timestamp;
  16.     my_current_timestamp = new Date();
  17.     return my_current_timestamp.getTime();
  18. }
  19.   
  20. function dragStart(event, id) 
  21. {    dragging = true;
  22.     
  23.     //*************************
  24.     //*  Disable nice titles  *
  25.     //*************************
  26.     supressNiceTitles = true;
  27.     
  28.     var el, x;      
  29.     dragObj.elNode = document.getElementById(id);
  30.     
  31.     // Get cursor position with respect to the page.
  32.     x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
  33.     dragLastX = x;
  34.     
  35.       // Save starting positions of cursor and element.
  36.     dragObj.cursorStartX = x;
  37.       dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);
  38.       
  39.       // Capture mousemove and mouseup events on the page.
  40.     document.attachEvent("onmousemove", dragGo);
  41.     document.attachEvent("onmouseup", dragStop);
  42.     window.event.cancelBubble = true;
  43.     window.event.returnValue = false;
  44. }
  45.  
  46.  
  47. function dragGo(event) 
  48. {    var x;
  49.     
  50.       // Get cursor position with respect to the page.
  51.     x = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
  52.     
  53.     // Move drag element by the same amount the cursor has moved.
  54.       dragIt(x, false);
  55.   
  56.       window.event.cancelBubble = true;
  57.     window.event.returnValue = false;
  58.     
  59.     dragLastTime = GetCurrentTime();
  60.     
  61.     if (x > dragLastX) 
  62.     {    dragDirection = "R"; 
  63.         dragDistance = x - dragLastX;
  64.     }
  65.     else
  66.     {    dragDirection = "L";
  67.         dragDistance = dragLastX - x;
  68.     }
  69.     
  70.     dragLastX = x;
  71. }
  72.  
  73.  
  74. function dragIt(x, calledFromCreeper)
  75. {    if (calledFromCreeper == true)
  76.     {    if (creeping == false) 
  77.         {    return;
  78.         }
  79.         else
  80.         {    if (oldX != undefined) 
  81.             {    if (dragDirection == "L")
  82.                 {    if (oldX < x) return;
  83.                 }
  84.                 else
  85.                 {    if (oldX > x) return;
  86.                 }    
  87.             }
  88.             
  89.             oldX = x;
  90.         }
  91.     }
  92.     
  93.     if (dragObj.elNode.scrollWidth > document.body.clientWidth)
  94.       {    if (((parseInt(dragObj.elStartLeft) + x - dragObj.cursorStartX) + dragObj.elNode.scrollWidth) < document.body.clientWidth)
  95.         {    dragObj.elNode.style.left = (document.body.clientWidth - dragObj.elNode.scrollWidth - 7) + "px";
  96.             dragObj.elNode.style.top = dragObj.elNode.style.top;
  97.         } 
  98.         else if (parseInt(dragObj.elStartLeft) + x - dragObj.cursorStartX > 32) 
  99.         {    dragObj.elStartLeft = "32" + "px";
  100.             dragStop(event);
  101.         } 
  102.         else
  103.         {    try
  104.             {    dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  105.                 dragObj.elNode.style.top = dragObj.elNode.style.top;
  106.             }
  107.             catch(err)
  108.             {    if (dragging == true)
  109.                 {    dragStop(event);
  110.                     dragObj.elStartLeft = "32px";                    
  111.                 }                
  112.             } 
  113.         }
  114.     }
  115. }
  116.  
  117.  
  118. function dragStop(event) 
  119. {    dragging = false;
  120.     
  121.     //*************************************************
  122.     //*  Stop capturing mousemove and mouseup events  *
  123.     //*************************************************
  124.     document.detachEvent("onmousemove", dragGo);
  125.     document.detachEvent("onmouseup", dragStop);
  126.     
  127.     if (isIE7 == true)
  128.      {    if ((GetCurrentTime() - dragLastTime) < 50) 
  129.         {    dragCreep();
  130.         }
  131.         else
  132.         {    //***************************
  133.             //*  Re-enable nice titles  *
  134.             //***************************
  135.             supressNiceTitles = false;
  136.         }
  137.      }
  138.      else
  139.      {    if ((GetCurrentTime() - dragLastTime) < 40) 
  140.         {    dragCreep();
  141.         }
  142.         else
  143.         {    //***************************
  144.             //*  Re-enable nice titles  *
  145.             //***************************
  146.             supressNiceTitles = false;
  147.         } 
  148.      }
  149. }
  150.  
  151.  
  152. function dragCreep()
  153. {    if (dragging == true) return;
  154.     creeping = true;
  155.  
  156.     var creepTime;
  157.     var creepDistance;
  158.     var creepStep;
  159.     var x = dragLastX;
  160.  
  161.     if (isIE7 == true)
  162.     {    creepTime = 30;
  163.         creepStep = 2;
  164.     
  165.         if (dragDistance < 10)
  166.             creepDistance = 14;
  167.         else if (dragDistance < 20)
  168.             creepDistance = 30;
  169.         else if (dragDistance < 30)
  170.              creepDistance = 40;
  171.         else
  172.             creepDistance = 50;
  173.     }
  174.     else 
  175.     {    creepTime = 20;
  176.         creepStep = 3;
  177.         
  178.         if (dragDistance < 5)
  179.                creepDistance = 10;
  180.         else if (dragDistance < 10)
  181.                creepDistance = 20;
  182.           else if (dragDistance < 20)
  183.             creepDistance = 30;
  184.           else if (dragDistance < 30)
  185.             creepDistance = 40;
  186.           else
  187.                creepDistance = 50;    
  188.     }    
  189.         
  190.     while (creepDistance > 0)
  191.     {    if (creeping == false) return;
  192.         
  193.         if (dragDirection == "L")
  194.             x = x - creepDistance;
  195.         else
  196.             x = x + creepDistance;
  197.                 
  198.         creepDistance = creepDistance - creepStep;
  199.         if (creepDistance <= 0) 
  200.         {    //***************************
  201.             //*  Re-enable nice titles  *
  202.             //***************************
  203.             setTimeout("supressNiceTitles = false", creepTime);
  204.             return;
  205.         }
  206.             
  207.         setTimeout("dragIt(" + x + ",true)", creepTime);
  208.         creepTime = creepTime + 30;        
  209.     }
  210. }